From bc882a679d7e51baf1e61d31cfa75202e5a70e9b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 31 Jan 2016 12:05:35 -0500 Subject: [PATCH] gtk-launch: Add --version Support --version. Also improve the --help output cosmetically. --- docs/reference/gtk/gtk-launch.xml | 9 ++++++++- gtk/gtk-launch.c | 29 +++++++++++++++++++---------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/docs/reference/gtk/gtk-launch.xml b/docs/reference/gtk/gtk-launch.xml index 1b2ba7b7c2..86ffe6dbf3 100644 --- a/docs/reference/gtk/gtk-launch.xml +++ b/docs/reference/gtk/gtk-launch.xml @@ -31,7 +31,8 @@ gtk-launch -APPLICATION +OPTION +APPLICATION URI @@ -62,6 +63,12 @@ application. Prints a short help text and exits. + + + + Prints the program version and exits. + + diff --git a/gtk/gtk-launch.c b/gtk/gtk-launch.c index 15d183bc20..576a449559 100644 --- a/gtk/gtk-launch.c +++ b/gtk/gtk-launch.c @@ -33,9 +33,11 @@ #endif #include +static gboolean show_version; static gchar **args = NULL; static GOptionEntry entries[] = { + { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, NULL, NULL }, { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL, NULL }, { NULL} }; @@ -66,14 +68,14 @@ main (int argc, char *argv[]) #endif /* Translators: this message will appear immediately after the */ - /* usage string - Usage: COMMAND [OPTION]… */ + /* usage string - Usage: COMMAND [OPTION...] */ context = - g_option_context_new (_("APPLICATION [URI…] — launch an APPLICATION with URI.")); + g_option_context_new (_("APPLICATION [URI...] — launch an APPLICATION")); /* Translators: this message will appear after the usage string */ /* and before the list of options. */ - summary = _("Launch specified application by its desktop file info\n" - "optionally passing list of URIs as arguments."); + summary = _("Launch an application (specified by its desktop file name),\n" + "optionally passing one or more URIs as arguments."); g_option_context_set_summary (context, summary); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_option_context_add_group (context, gtk_get_option_group (FALSE)); @@ -86,21 +88,28 @@ main (int argc, char *argv[]) { g_printerr (_("Error parsing commandline options: %s\n"), error->message); g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), - g_get_prgname ()); + g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); - g_error_free(error); + g_error_free (error); return 1; } + if (show_version) + { + g_print ("%d.%d.%d\n", + gtk_get_major_version (), + gtk_get_minor_version (), + gtk_get_micro_version ()); + return 0; + } + if (!args) { /* Translators: the %s is the program name. This error message */ /* means the user is calling gtk-launch without any argument. */ g_printerr (_("%s: missing application name"), g_get_prgname ()); g_printerr ("\n"); - g_printerr (_("Try \"%s --help\" for more information."), - g_get_prgname ()); + g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); return 1; } @@ -112,7 +121,7 @@ main (int argc, char *argv[]) #ifdef G_OS_UNIX if (g_str_has_suffix (app_name, ".desktop")) desktop_file_name = g_strdup (app_name); - else + else desktop_file_name = g_strconcat (app_name, ".desktop", NULL); info = G_APP_INFO (g_desktop_app_info_new (desktop_file_name)); g_free (desktop_file_name); -- 2.30.2